<?php
namespace app\admin\controller;
use app\common\model\ProjectLog;
use think\Db;

class ProjectLogController extends BaseController
{
    public function _initialize(){
        $this->project_log_model = new ProjectLog();
    }
    /**
     * 获取项目消息
     */
    public function getList()
    {
        $page = $this->request->param('page');
        $page_size = $this->request->param('page_size');
        $is_comment = $this->request->param('is_comment');
        if($is_comment == 'first'){
            $is_comment = 0;
        }else{
            $is_comment = 1;
        }
        if(empty($page_size)){
            $page_size = 10;
        }
        // 获取最新消息
        $count = $this->project_log_model->where(['is_comment'=>0])->count();
        $data = $this->project_log_model->where(['is_comment'=>$is_comment])->paginate($page_size, false, ['query' => request()->param(),'page'=>$page]);
        $this->success('获取成功','',['count'=>$count,'data'=>$data]);
    }
    public function setComment()
    {
        $where['id'] = input('post.id');
        if(empty($where['id'] )){//
            $where['is_comment'] = 0;
            unset($where['id']);
        }
        $res = $this->project_log_model->where($where)->update(['is_comment'=>1]);
        if(!empty($res)){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }

    }
}